  (function () {


    var style = `
      .task_config_form{
        padding: 20px;
      }
      .task_config_form .layui-form-label{
        width: 115px;
      }
      .task_config_form .layui-input-block{
        margin-left: 145px;
      }
    `;

    var template = `
  <div class="layui-form task_config_form" lay-filter="task_config_form">
  <input type="hidden" name="task_id" :value="task.task_id">
  <div class="layui-form-item">
      <label class="layui-form-label">任务名称</label>
      <div class="layui-input-block">
        <input type="text" name="task_name" required  :value="task.task_name" lay-verify="required" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">根地址</label>
      <div class="layui-input-block">
        <input type="text" name="root_url" required  :value="task.root_url" lay-verify="required" placeholder="请输入根地址" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">采集根地址脚本</label>
      <div class="layui-input-block">
        <textarea rows="10" name="spider_root_url_script" lay-verify="required" placeholder="请输入采集根地址脚本" :value="taskConfig.spider_root_url_script" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">采集内容URL脚本</label>
      <div class="layui-input-block">
        <textarea rows="10" name="spider_content_url_script" lay-verify="required" placeholder="请输入采集URL脚本" :value="taskConfig.spider_content_url_script" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">采集内容脚本</label>
      <div class="layui-input-block">
        <textarea rows="10" name="spider_content_script" lay-verify="required" placeholder="请输入采集内容脚本" :value="taskConfig.spider_content_script" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">采集超时时间</label>
      <div class="layui-input-inline">
        <input type="number" name="spider_timeout" required  :value="taskConfig.spider_timeout" lay-verify="required" placeholder="采集超时时间" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux">ms</div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">定时器Cron</label>
      <div class="layui-input-block">
        <textarea rows="3" name="spider_crons" placeholder="请输入任务定时执行cron表达式，多个表达式换行隔开" :value="taskConfig.spider_crons" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="config_save_btn" >保存</button>
      </div>
    </div>
  </div>
`
    return {
      data() {
        return {
        }
      },
      updated: function () {
        layui.form.render();
        var that = this;
        layui.form.on('submit(config_save_btn)', function (data) {
          that.saveConfig(data)
          return false;
        });
      },
      mounted: function () {
        layui.form.render();
        var that = this;
        layui.form.on('submit(config_save_btn)', function (data) {
          that.saveConfig(data)
          return false;
        });
      },
      props: ["task"],
      methods: {
        saveConfig: function (data) {
          var result = ipcRenderer.sendSync("saveTaskInfo", data.field);
          if (result.success) {
            layui.layer.msg("保存成功！");
            this.$emit("save-success", result.data);
            result = ipcRenderer.sendSync("updateCronTask", result.data);
            if(!result.success) {
              layui.layer.msg("保存成功，定时器任务更新失败！" + result.error);
            }
          } else {
            layui.layer.msg("保存失败！" + result.error);
          }
          return false;
        },
      },
      computed: {
        taskConfig: function () {
          var result = ipcRenderer.sendSync("getTaskConfig", this.task.task_id);
          if (result.success && result.data && result.data.length > 0) {
            return result.data[0];
          } else {
            return {
              spider_root_url_script: `return ['${this.task.root_url}']`,
              spider_content_url_script: `return []`,
              spider_content_script: `return {title: document.title}`,
              spider_timeout: 3000,
              spider_crons: null,
            }
          }
        }
      },
      watch: {
      },
      template: template,
      style: style
    }
  })()